package com.xu.cloud.codegenerator.convert;

import com.xu.cloud.codegenerator.pojo.domain.ColumnDO;
import com.xu.cloud.codegenerator.pojo.dto.ColumnDTO;

import java.util.List;
import java.util.stream.Collectors;

/**
 * ColumnEntity类转换器
 *
 * @author xuguan
 * @since 2024/1/26
 */
public class ColumnEntityConverter {

    public static ColumnDTO convertColumnDO(ColumnDO columnDO) {
        if (columnDO == null) {
            return null;
        }
        final ColumnDTO columnDTO = new ColumnDTO();
        columnDTO.setColumnName(columnDO.getColumnName());
        columnDTO.setDataType(columnDO.getDataType());
        columnDTO.setColumnComment(columnDO.getColumnComment());
        columnDTO.setColumnKey(columnDO.getColumnKey());
        columnDTO.setExtra(columnDO.getExtra());
        return columnDTO;
    }

    public static List<ColumnDTO> convertColumnDOList(List<ColumnDO> columnDOList) {
        if (columnDOList == null) {
            return null;
        }
        return columnDOList.stream()
                .map(ColumnEntityConverter::convertColumnDO)
                .collect(Collectors.toList());
    }
}
